package com.ymt.reliable.message.exceptionretry.service;

import com.ymt.reliable.message.domain.TransactionMessage;
import com.ymt.reliable.message.domain.TransactionMessageFactory;
import com.ymt.reliable.message.exceptionretry.service.impl.MessageExceptionRetryBaseOnDelayedQueue;
import com.ymt.reliable.message.exceptionretry.task.Task;
import com.ymt.reliable.message.exceptionretry.task.TaskFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MessageExceptionRetryServiceTestMain {
    private static final Logger LOGGER = LoggerFactory.getLogger(MessageExceptionRetryServiceTestMain.class);
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static void main(String[] args) {
        Date date = new Date();
        LOGGER.info(">>> 当前时间{}", DATE_FORMAT.format(date));

        TransactionMessage m1 = TransactionMessageFactory.createTransactionMessage("m1", "test", null);
        m1.setMessageId("1");
        m1.setLastPushTime(date);
        Task task1 = TaskFactory.createTask(m1, 1000L * 60L);

        TransactionMessage m2 = TransactionMessageFactory.createTransactionMessage("m2", "test", null);
        m2.setMessageId("2");
        m2.setLastPushTime(date);
        Task task2 = TaskFactory.createTask(m2, 2000L * 60L);

        MessageExceptionRetryBaseOnDelayedQueue messageExceptionRetryBaseOnDelayedQueue = new MessageExceptionRetryBaseOnDelayedQueue();
        messageExceptionRetryBaseOnDelayedQueue.addTask(task1);
        messageExceptionRetryBaseOnDelayedQueue.addTask(task2);
        messageExceptionRetryBaseOnDelayedQueue.start();
    }
}
